package com.finance.cooperate.feature.service.impl;

import com.finance.cooperate.common.utils.StringUtil;
import com.finance.cooperate.dao.entity.primary.CrcScores;
import com.finance.cooperate.dao.local.scope.CooperateRequestScope;
import com.finance.cooperate.dao.repository.primary.CrcScoresRepository;
import com.finance.cooperate.feature.service.CrcScoresService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName CrcScoresServiceImpl
 * @Description TODO
 * @Author shen
 * @Date 2023/8/10 17:43
 * @Modify ...
 */
@Slf4j
@Service
public class CrcScoresServiceImpl implements CrcScoresService {

    @Autowired
    private CrcScoresRepository scoresRepository;

    @Autowired
    private CooperateRequestScope requestScope;


    @Override
    public Integer getScore(String uid) {

        String applyId = requestScope.getApplyId();

        CrcScores crcScores = scoresRepository.findFirstByApplyIdOrderByCreateTimeDesc(applyId);

        if (crcScores != null && !StringUtil.isEmptyOrNvl(crcScores.getValor())) {

            return Integer.parseInt(crcScores.getValor());
        }

        return null;
    }

}
